var data1 = "";
$(function () {
    $.post("/querybyuid",function (data) {
        data1=data;
        // let s = JSON.stringify(data);
        let u_name = data[0].u_name;
        let u_email = data[0].u_email;
        let u_phone = data[0].u_phone;
        let u_sex = data[0].u_sex;
        if (u_sex===0){
            u_sex = "男";
        }else {u_sex = "女"}
        let u_university = data[0].u_university;
        let u_entrytime = data[0].u_entrytime;
        let u_quit = data[0].u_quit;
        if (u_quit===0){
            u_quit = "未离职";
        }else {u_quit = "离职"}
        let departmentname = data[0].departmentname;
        let postname = data[0].postname;
        $("#utitle").val(u_name);
        $("#uemail").val(u_email);
        $("#uphone").val(u_phone);
        $("#usex").val(u_sex);
        $("#uuniversity").val(u_university);
        $("#uentrytime").val(u_entrytime);
        $("#uquit").val(u_quit);
        $("#udepartment").val(departmentname);
        $("#upost").val(postname);
    },"json")
})

layui.use('layer', function() {
    let layer = layui.layer;

})
//修改按钮
function modify() {
        layer.open({
            type: 1,
            title: "信息修改",
            skin: 'layui-layer-rim', //加上边框
            area: ['620px', '580px'], //宽高
            content: '  <form class="layui-form" action="" lay-filter="form1">\n' +
                '                <div class="layui-form-item">\n' +
                '                    <label class="layui-form-label">姓名</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="text" name="Name" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" id="fname">\n' +
                '                    </div>\n' +
                '                    <label class="layui-form-label">邮箱</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="text" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input" id="femail">\n' +
                '                    </div>\n' +
                '                    <label class="layui-form-label">电话</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="text" name="phone" required  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input" id="fphone">\n' +
                '                    </div>\n' +
                '                    <label class="layui-form-label">毕业院校</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="text" name="university" required  lay-verify="required" placeholder="请输入毕业院校" autocomplete="off" class="layui-input" id="funiversity">\n' +
                '                    </div>\n' +
                '                    <label class="layui-form-label">入职时间</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="text" name="entrytime" class="layui-input" id="test1" autocomplete="off">\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '                <div class="layui-form-item">\n' +
                '                    <label class="layui-form-label">请选择部门</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <select name="departmentId" lay-verify="required">\n' +
                '                            <option value=""></option>\n' +
                '                            <option value="开发部">开发部</option>\n' +
                '                            <option value="人力资源部">人力资源部</option>\n' +
                '                            <option value="财务部">财务部</option>\n' +
                '                            <option value="测试部">测试部</option>\n' +
                '                            <option value="网络工程部">网络工程部</option>\n' +
                '                            <option value="行政部">行政部</option>\n' +
                '                            <option value="硬件维护部">硬件维护部</option>\n' +
                '                        </select>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '                <div class="layui-form-item">\n' +
                '                    <label class="layui-form-label">请选择岗位</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <select name="postId" lay-verify="required">\n' +
                '                            <option value=""></option>\n' +
                '                            <option value="技术总监">技术总监</option>\n' +
                '                            <option value="部门经理">部门经理</option>\n' +
                '                            <option value="项目经理">项目经理</option>\n' +
                '                            <option value="测试经理">测试经理</option>\n' +
                '                            <option value="程序员">程序员</option>\n' +
                '                            <option value="维护人员">维护人员</option>\n' +
                '                            <option value="调研人员">调研人员</option>\n' +
                '                            <option value="总经理">总经理</option>\n' +
                '                            <option value="产品经理">产品经理</option>\n' +
                '                            <option value="系统分析员">系统分析员</option>\n' +
                '                            <option value="测试岗位修改">测试岗位修改</option>\n' +
                '                        </select>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '                <div class="layui-form-item">\n' +
                '                    <label class="layui-form-label">单选框</label>\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <input type="radio" name="sex" value="男" title="男">\n' +
                '                        <input type="radio" name="sex" value="女" title="女" checked>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '\n' +
                '                <div class="layui-form-item">\n' +
                '                    <div class="layui-input-block">\n' +
                '                        <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="sub()">立即提交</button>\n' +
                '                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '            </form>',
            success: function () {
                layui.use(['laydate','form'],function () {
                    let laydate = layui.laydate;
                    var form = layui.form;
                    form.render();
                    laydate.render({
                        elem: '#test1' //指定元素
                        , show: true //直接显示
                    });
                })
                    let u_name = data1[0].u_name;
                    let u_email = data1[0].u_email;
                    let u_phone = data1[0].u_phone;
                    let u_university = data1[0].u_university;
                    $("#fname").val(u_name);
                    $("#femail").val(u_email);
                    $("#fphone").val(u_phone);
                    $("#funiversity").val(u_university);
            }
        })
}

function sub() {
    var s = "";
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
           s = JSON.stringify(data.field);
            $.post("/insertinfo",{"s":s},function (data) {
                if (data.code===500){
                    alert(data.info);
                }else {
                    window.location.href = "staff.html";
                }
            },"json")
        });
    });

}